package com.bci.pwtz.service.impl;

import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import com.bci.pwtz.exception.PwtzDatabaseException;
import com.bci.pwtz.mysql.dao.DictionaryAuditMapper;
import com.bci.pwtz.mysql.model.Dictionary;
import com.bci.pwtz.service.DictionaryAuditService;
@Service
public class DictionaryAuditServiceImpl implements DictionaryAuditService
{

    DictionaryAuditMapper dictionaryAuditMapper;
    private static Logger logger=Logger.getLogger(DictionaryAuditServiceImpl.class);
    public DictionaryAuditMapper getDictionaryAuditMapper()
    {
        return dictionaryAuditMapper;
    }

    public void setDictionaryAuditMapper(DictionaryAuditMapper dictionaryAuditMapper)
    {
        this.dictionaryAuditMapper = dictionaryAuditMapper;
    }

    @Override
    public void add(String type, String value) throws PwtzDatabaseException
    {
        if(logger.isDebugEnabled()){
            logger.debug("add:type="+type+"value"+value);
        }
        if(value==null||value==""){
            if(logger.isDebugEnabled()){
                logger.debug("add,value is null or value is blank");
            }
        }
        try{
            Dictionary dictionary=new Dictionary();
            dictionary.setDictionaryTypeId(Long.parseLong(type));
            dictionary.setDictionaryValue(value);
            dictionary.setRank(0l);
            int result=dictionaryAuditMapper.insertSelective(dictionary);
            System.out.println(result);
        }catch(Exception e){
            logger.error(ExceptionUtils.getStackTrace(e));
            throw new PwtzDatabaseException();
        }
    }

}
